// pages/dingchang/dingchang.js
// 获取应用实例
const app = getApp()
const api = require('../../../api/index.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    display:""
  },
  quxiao: function (e) {
    var subject_id = e.currentTarget.id
    this.setData({
      display: "block",
      subject_id: subject_id
    })
  },
  hideview: function () {
    this.setData({
      display: "none"
    })
  },
  phoneCall: function () {
    var that = this
    var subject_id = this.data.subject_id
    console.log(this.data.subject_id)
    var data = {
      subject_id: subject_id
    }
    api.reservation(data, (res) => {
      console.log(res,"这是调用取消订单返回的数据")
      if (res.data.code == 200) {
        //刷新页面
        that.onShow()
        //关闭弹窗
        that.setData({
          display: "none"
        })
      }
    })
  },

  fukuan1:function(e){
    // console.log(e,"这是当前的订单ID，数量。。。。")
    var openid_wechat = wx.getStorageSync("openid")
    var data = {
      type:1,
      order_sn:e.currentTarget.dataset.order,
      e_id:e.currentTarget.dataset.id,
      num:e.currentTarget.dataset.num,
      is_vip_day: e.currentTarget.dataset.isvip,
      openid_wechat: openid_wechat.openid
    }
    console.log(data, "这是调用付款接口要传的参数")
    api.orderwe(data, (res) => {
      console.log(res, "这是调用付款接口返回的数据")
      wx.requestPayment({
        timeStamp: res.data.result.timeStamp,
        nonceStr: res.data.result.nonceStr,
        package: res.data.result.package,
        signType: res.data.result.signType,
        paySign: res.data.result.paySign,
        // order_sn: res.data.result.order_sn,
        success(res) { 
          console.log(res)
        },
        fail(res) { }
      })
    })
  },

  fukuan0:function(e){
    var that = this
    // console.log(e, "这是当前的订单ID，数量。。。。")
    var openid_wechat = wx.getStorageSync("openid")
    var data = {
      order_sn: e.currentTarget.dataset.order
    }
    console.log(data, "这是调用付款接口要传的参数")
    api.huiyuanzhifu(data, (res) => {
      console.log(res, "这是调用付款接口返回的数据")
      that.onShow()
    })
  },
  

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (data) {
    

  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示，这个函数是监听页面显示的，把掉接口的函数放在这，就不用强制刷新了
   */
  onShow: function (data) {
    var that = this
    api.liebiao(data, (res) => {
      console.log(res)
      that.setData({
        result: res.data.result
      })
    })
  },
  xiangqing: function (e) {

    wx.navigateTo({
      url: '../fukuan/fukuan?id=' + e.currentTarget.id
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})